#region Using Statements

using Merlba.MVVM.Module.Football.Services;
using Merlba.MVVM.Module.Football.ViewModels;
using Merlba.MVVM.Module.Football.Views;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;

#endregion

namespace Merlba.MVVM.Module.Football
{
    public class FootballModule : IModule
    {
        private readonly IUnityContainer _container;
        private readonly IRegionManager _regionManager;

        public FootballModule(IUnityContainer container, IRegionManager regionManager)
        {
            _container = container;
            _regionManager = regionManager;
        }

        #region IModule Members

        public void Initialize()
        {
            RegisterViewsAndServices();
            var presentationModel = _container.Resolve<IScoreboardViewModel>();
            IRegion mainRegion = _regionManager.Regions[Infrastructure.RegionNames.MainRegion];
            mainRegion.Add(presentationModel.View);
            presentationModel.Initialise();
        }

        #endregion

        private void RegisterViewsAndServices()
        {
            _container.RegisterType<IFootballService,FootballService>();

            _container.RegisterType<IFootballViewModel, FootballViewModel>();
            _container.RegisterType(typeof(FootballView));

            _container.RegisterType<IScoreboardViewModel, ScoreboardViewModel>();
            _container.RegisterType(typeof(ScoreBoardView)); 

        }
    }
}